<?php
/**
 * Open Framework
 *
 * LICENSE
 *
 *this file is a template.
 *
 *
 * @category   
 * @package    
 * @subpackage 
 * @copyright  copyright
 * @license    $Id: file.php 5308 2008-12-13 17:18:45Z fy $
 */


/**
 * Class 
 *
 * @category   
 * @package    
 * @subpackage 
 * @copyright  
 * @license    
 */
class FreeY_Db_Table_Insert extends FreeY_Db_Table_Abstract
{
	/**
	 * _method_info
	 *
	 * @param $var
	 * @return viod
	 */
	public function start($input)
	{
		$this->input = $input;
	}
	/**
	 * _method_info
	 *
	 * @param $var
	 * @return viod
	 */
	public function run()
	{
		$tablename = $this->input['tablename'];
		$data = $this->input['data'];
		$sql = $this->_getSql($tablename,$data);
		return $sql;
	}
	/**
	 * _method_info
	 *
	 * @param $var
	 * @return viod
	 */
	protected function _getSql($tablename,$data)
	{
		if(!is_array($data))
		{
			return '';
		}
		foreach($data as $key=>$value)
		{
			$k[] = $key;
			if(! is_numeric($value))
			{
				$v[] = "'".$value."'";
			}
			else 
			{
				$v[] = $value;
			}
		}		
		$kstr=join(',',$k);
		$vstr=join(',',$v);
		$sql='insert into '.$tablename.'('.$kstr.') values('.$vstr.')';
		return $sql;
	}
}
//file end--------------------------------------------------------->
?>